import request from '@/utils/request'

// 查询内部转账记录列表
export function listTransfer(query) {
  return request({
    url: '/system/transfer/list',
    method: 'get',
    params: {
      ...query,
      dateStart: query.dateStart,
      dateEnd: query.dateEnd,
      voucherDateStart: query.voucherDateStart,
      voucherDateEnd: query.voucherDateEnd,
      voucherNoStart: query.voucherNoStart,
      voucherNoEnd: query.voucherNoEnd,
      accountOut: query.accountOut,
      accountJoin: query.accountJoin
    }
  })
}

// 查询内部转账记录详细
export function getTransfer(id) {
  return request({
    url: '/system/transfer/' + id,
    method: 'get'
  })
}

// 新增内部转账记录
export function addTransfer(data) {
  return request({
    url: '/system/transfer',
    method: 'post',
    data: data
  })
}

// 修改内部转账记录
export function updateTransfer(data) {
  return request({
    url: '/system/transfer',
    method: 'put',
    data: data
  })
}

// 删除内部转账记录
export function delTransfer(id) {
  return request({
    url: '/system/transfer/' + id,
    method: 'delete'
  })
}

// 批量删除内部转账记录
export function delTransfers(ids) {
  return request({
    url: '/system/transfer/' + ids,
    method: 'delete'
  })
}

// 导入内部转账数据
export function importData(data) {
  return request({
    url: '/system/transfer/importData',
    method: 'post',
    data: data
  })
}

// 下载内部转账导入模板
export function importTemplate() {
  return request({
    url: '/system/transfer/importTemplate',
    method: 'get'
  })
}

// 生成凭证
export function generateVoucher(data) {
  console.log("API发送数据:", data);
  
  // 确保transferId是数字类型
  const sendData = {
    ...data,
    id: Number(data.id)
  };
  
  return request({
    url: '/system/transfer/generateVoucher',
    method: 'post',
    timeout: 30000, // 增加超时时间到30秒
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: sendData
  })
}
